#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>

#define SWAP(a, b)	((a) ^ (b) && ((a) ^= ((b) ^= (a)), (b) ^= (a)))

/* {{{ unused */
static int
Quicksort_3w_part(int *set, const int n, const int lo, const int up)
{
	register int i, j;
	int mid = -1;

	i = 0;
	j = n - 1;
	while (i < j) {
		while (set[i] <= up)
			++i;
		while (set[j] > up && j > i)
			--j;

		if (i < j) {
			SWAP(set[i], set[j]);
			++i;
			--j;
		} else {
			break;
		}
	}
	mid = j;

	i = 0;
	j = mid;
	while (i < j) {
		while (set[i] < lo)
			++i;
		while (set[j] >= lo && j > i)
			--j;

		if (i < j) {
			SWAP(set[i], set[j]);
			++i;
			--j;
		} else {
			break;
		}
	}

	return mid - j + 1;
}
/* }}} */

/* {{{ fancy Mergesort */
int
Mergesort__merge(int *p1, int *p2, long long unsigned *mc, const int depth,
                 const int left, const int mid, const int right)
{
	int *array, *cpyarray;
	register int i = left, j = mid + 1, s = left;

#ifdef D
	fprintf(stderr, "mc=%llu, depth=%d, left=%d, mid=%d, right=%d\n",
			*mc, depth, left, mid, right);
#endif

	//if (*mc & 1)
	if (depth & 1)
		array = p1, cpyarray = p2;
	else
		array = p2, cpyarray = p1;

	while (i <= mid && j <= right) {
		if (array[i] <= array[j]) {
			cpyarray[s++] = array[i++];
		} else {
			cpyarray[s++] = array[j++];
		}
	}

	while (i <= mid)
		cpyarray[s++] = array[i++];
	while (j <= right)
		cpyarray[s++] = array[j++];

	assert(i == mid + 1);
	assert(j == right + 1);
	assert(s == right + 1);

	++*mc;
	return 0;
}

int
Mergesort__main(int *a, int *b, long long unsigned *mc, const int depth,
                const int L, const int R)
{
	int M = (L + R) / 2;

	if (L < R) {
		Mergesort__main(a, b, mc, depth + 1, L, M);
		Mergesort__main(a, b, mc, depth + 1, M + 1, R);
		Mergesort__merge(a, b, mc, depth, L, M, R);
	}

	return 0;
}

/*
 * wrapper func
 */
int
Mergesort(int *array, const int n)
{
	int *tmp_array;
	static long long unsigned merge_count = 0;
	int depth = 0;

	tmp_array = malloc(n * sizeof *tmp_array);
	(void) memcpy(tmp_array, array, n * sizeof *array);

	Mergesort__main(array, tmp_array, &merge_count, depth, 0, n - 1);

#ifdef D
	fprintf(stderr, "merge_count=%llu\n", merge_count);
#endif

	free(tmp_array);
	return 0;
}
/* }}} */

int
binsearch(const int key, const int *array, const int n)
{
	int left = 0, right = n - 1;
	int mid = (left + right) / 2; /* :D */

	while (left < right) {
		mid = (left + right) / 2;

		if (key == array[mid]) {
			return mid;
		} else if (key > array[mid]) {
			left = mid + 1;
		} else {
			right = mid;
		}
	}

	return left;
}

int
main(int argc, char **argv)
{
	int n, k, *set, lo, up, i;
	register int up_idx, lo_idx;

	scanf("%d", &n);
	set = malloc(n * sizeof *set);
	for (i = 0; i < n; i++)
		scanf("%d", set + i);
	Mergesort(set, n);

	scanf("%d", &k);
	fprintf(stderr, "n=%d k=%d\n", n, k);
	for (i = 0; i < k; i++) {
		if (scanf("%d%d", &lo, &up) != 2)
			fprintf(stderr, "something's gone wrong while reading input data\n");

		up_idx = binsearch(up, set, n);
		if (set[up_idx] <= up)
			while (up_idx + 1 < n && set[up_idx] == set[up_idx + 1] && set[up_idx] == up)
				++up_idx;
		else
			while (up_idx >= 0 && set[up_idx] > up)
				--up_idx;

		lo_idx = binsearch(lo, set, n);
		if (set[lo_idx] >= lo)
			while (lo_idx > 0 && set[lo_idx] == set[lo_idx - 1] && set[lo_idx] == lo)
				--lo_idx;
		else
			while (lo_idx < n && set[lo_idx] < lo)
				++lo_idx;

		printf("%d\n", up_idx - lo_idx + 1);
	}

	free(set);
	return 0;
}
